/*
 * my_tracer.h
 *
 *  Created on: Aug 29, 2013
 *      Author: killerg
 */

#ifndef MY_TRACER_H_
#define MY_TRACER_H_

#include <vector>
#include <string>
#include <stdarg.h>

template<int T>
struct tracer_t {
    static std::vector<std::string> _strs;
    tracer_t(const char* fmt, ...) {
        va_list p;
        va_start(p, fmt);
        static char buffer[1000];
        vsprintf(buffer, fmt, p);
        va_end(p);
        _strs.emplace_back(buffer);

        for (uint i=0; i<_strs.size(); ++i)
            printf("  ");
        printf(">%s\n", _strs.back().c_str());
    }
    ~tracer_t() {
        for (uint i=0; i<_strs.size(); ++i)
            printf("  ");
        printf("<%s\n", _strs.back().c_str());
        _strs.pop_back();
    }

    static void log(const char* fmt, ...) {
        va_list p;
        va_start(p, fmt);

        for (uint i=0; i<_strs.size() + 1; ++i)
            printf("  ");

        static char buffer[1000];
        vsprintf(buffer, fmt, p);
        printf("%s\n", buffer);

        va_end(p);
    }
};

template<int T>
std::vector<std::string> tracer_t<T>::_strs;



#endif /* MY_TRACER_H_ */
